//
//  ABBViewController.swift
//  PassValueDemo
//
//  Created by MAC on 2020/8/25.
//  Copyright © 2020 MAC. All rights reserved.
//

import UIKit

class ABBViewController: UIViewController {

    //声明全局闭包（Block）
    var bbchange:((_ title:String)->Void)?
    //声明全局变量，并初始化
     var textF = UITextField()
    
    override func viewDidLoad() {
        super.viewDidLoad()

        //传值按钮
        let ymBtn_01 = UIButton()
        ymBtn_01.frame = CGRect(x: 50, y: 130, width: view.frame.size.width - 100, height: 50)
        ymBtn_01.setTitle("跳转到上级页面，并传回值", for: .normal)
        ymBtn_01.backgroundColor = .brown
        ymBtn_01.tag = 10001
        ymBtn_01.addTarget(self, action: #selector(tiaozhuanyemianclick(sender:)), for: .touchUpInside)
        view.addSubview(ymBtn_01)
        
        //传值的输入框
        textF.frame = CGRect(x: 50, y: (ymBtn_01.frame.origin.y + ymBtn_01.frame.size.height) + 50, width: view.frame.size.width - 100, height: 50)
        textF.attributedPlaceholder = NSAttributedString(string: "请输入要传的值", attributes: [NSAttributedString.Key.foregroundColor : UIColor.init(red: 1.000, green: 1.000, blue: 1.000, alpha: 0.5)])
        textF.borderStyle = .line
        textF.textColor = .white
        textF.backgroundColor = UIColor.init(red: 0.283, green: 0.290, blue: 0.293, alpha: 1)
        view.addSubview(textF)
        
        //提示标签
        let textLabel_1 = UILabel()
        textLabel_1.font = .systemFont(ofSize: 20)
        textLabel_1.frame = CGRect(x: 50, y: (textF.frame.origin.y+textF.frame.size.height)+50, width: view.frame.size.width - 100, height: 50)
        textLabel_1.text = "请先上面的输入框中填写要传回的值"
        textLabel_1.numberOfLines = 0
        textLabel_1.lineBreakMode = .byWordWrapping
        textLabel_1.backgroundColor = UIColor.init(red: 0.238, green: 0.240, blue: 0.242, alpha: 0.5)
        textLabel_1.textColor = .yellow
        textLabel_1.font = .systemFont(ofSize: 15)
        textLabel_1.textAlignment = .center
        view.addSubview(textLabel_1)
        
    }
    //实现传值按钮的监听方法
    @objc func tiaozhuanyemianclick(sender:UIButton){
        bbchange?(textF.text!)
        self.navigationController?.popViewController(animated: true)
    }

}
